#pragma once

#include <stddef.h>
#include <mutex>

class CMemory
{
public:
    ~CMemory();
    static CMemory* GetInstance() //获取单例
	{			
		if(m_instance == NULL)
		{
			std::lock_guard<std::mutex> lock(m_mutex);
			if(m_instance == NULL)
			{				
				m_instance = new CMemory();
				static CGarhuishou cl; 
			}
		}
		return m_instance;
	}
    // 内部类起到延迟释放单例作用
	class CGarhuishou 
	{
	public:				
		~CGarhuishou()
		{
			if (CMemory::m_instance)
			{						
				delete CMemory::m_instance;
				CMemory::m_instance = NULL;				
			}
		}
	};

    // 分配内存
    void *AllocMemory(int memCount,bool ifmemset);
    // 释放内存
	void FreeMemory(void *point);

private:
    CMemory();
	CMemory(const CMemory&) = delete;
	CMemory& operator=(const CMemory&) = delete;
    static CMemory *m_instance;// 单例模式
	static std::mutex m_mutex;// 互斥锁
};

